package com.itheima.kafka.boot;

import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description:
 * @Version: V1.0
 */
@RestController
public class HelloController {

    @Autowired
    KafkaTemplate kafkaTemplate;


    @GetMapping("hello")
    public String hello(String msg) {
        // 参数1：topic
        // 参数2：消息内容
//        kafkaTemplate.send("boot-topic", msg+"Hello Boot Kafka!");

        Map map = new HashMap();
        map.put("k", "1");
        map.put("v", "2");

        kafkaTemplate.send("boot-topic", JSON.toJSONString(map));


        return "OK";

    }

}
